/*
 * Copyright (c) 2019, Beijing Aegean Soft. All rights reserved.
 *
 */

package com.inoteexpress.irpdataexport;

import org.springframework.beans.BeansException;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Service;

import java.io.IOException;

/*
 * SpringBoot 启动类
 * @author  Sunny
 * @date 2019/03/16
 */

@Service
@SpringBootApplication
public class IrpdataexportApplication implements ApplicationContextAware {
    private static ApplicationContext appCtx;

    public static void main(String[] args) {
        SpringApplication.run(IrpdataexportApplication.class, args);
        IrpRecordsExporter irp = appCtx.getBean(IrpRecordsExporter.class);
        String outdir = System.getenv("storepath");
        if (outdir == null) {
            System.out.println("Store path must be provide");
            System.exit(1);
        }
        try {
            irp.exportRecords(outdir);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        appCtx = applicationContext;
    }
}
